<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="编辑零售收银设置">
    <style type="text/css">
    </style>
    <script>

        jQuery(function () {
            ajaxSelect("${baseUrl}custom/custom/getAll.action","customId");
            ajaxSelects("${baseUrl}settAccount/settAccount/listVo.action",[
                {selectName:"cashSettAccountId"},
                {selectName:"cardSettAccountId"}]);

            ajaxSelect("${baseUrl}organization/store/getStores.action","storeId",undefined, function (data) {
                if (data !=null && data.length > 0) {
                    ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+data[0].id,"houseId");
                }
            });


        });

        layui.use(['form', 'layedit', 'laydate','element'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate;

            get("${baseUrl}sett/retailSet/getById.action?id=${id}", function (res) {
                if (res.code == 1){
                    ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+res.data.storeId,"houseId",undefined,function () {
                        formSetVal("form",res.data);
                    });
                } else {
                    errTip(res.msg);
                }
            });

            form.on('select(storeId)',function (data) {
                ajaxSelect("${baseUrl}organization/house/getHouseByStore.action?storeId="+data.value,"houseId");
            });

            form.on('submit(cancel)', function (data) {
                closeSubIframe();
            });

            form.on('submit(save)', function (data) {
                console.log(data.field);

                if(data.field.storeId == ""){
                    errTip("门店不能为空");
                    return false;
                }

                if(data.field.houseId == ""){
                    errTip("仓库不能为空");
                    return false;
                }

                if(data.field.cashSettAccountId == ""){
                    errTip("现金账户不能为空");
                    return false;
                }
                if(data.field.customId == ""){
                    errTip("默认客户不能为空");
                    return false;
                }

                post("${baseUrl}sett/retailSet/update.action",data.field, function (res) {
                    if (res.code == 1) {
                        refreshMainIframe("${baseUrl}sett/retailSet.action");
                        closeSubIframe();
                    } else {
                        errTip(res.msg);
                    }
                });
                return false;
            });
        });
    </script>
</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" action="" lay-filter="form">
            <input type="hidden" name="id" value="${id}">
            <h2 style="padding:40px 20px 0 20px;">基本信息</h2>
            <hr>
            <div class="layui-form-item">
                <label class="layui-form-label">所属门店</label>
                <div class="layui-input-inline">
                    <select name="storeId" lay-filter="storeId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">出库仓库</label>
                <div class="layui-input-inline">
                    <select name="houseId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">默认客户</label>
                <div class="layui-input-inline">
                    <select name="customId">
                    </select>
                </div>
            </div>


            <h2 style="padding: 20px 20px 0 20px">支付方式</h2>
            <p style="font-size: 12px;color: #aaaaaa;padding: 8px 20px 0 20px;">请选择零售收银时支持的付款方式。当选择了现金或银联卡支付时，则需设置对应的结算账户。</p>
            <hr>

            <div class="layui-form-item">
                <label class="layui-form-label">现金账户</label>
                <div class="layui-input-inline">
                    <select name="cashSettAccountId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">银行卡账户</label>
                <div class="layui-input-inline">
                    <select name="cardSettAccountId">
                    </select>
                </div>
            </div>


            <hr style="margin-top: 20px;">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="save">保存</button>
                    <button lay-submit lay-filter="cancel" class="layui-btn layui-btn-primary">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>